package pl.umk.mat.fred.unicore.urc.storagemanagement.dialogs;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class FindDialog extends Dialog {

	private Text text;
	private Button checkBox;
	String criteria;
	Boolean useRegexec;
	
	public FindDialog(Shell parentShell) {
	  super(parentShell);
  }

	protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite)super.createDialogArea(parent);
    GridLayout layout = new GridLayout(2, false);
    layout.marginBottom = 10;
    layout.marginTop = 10;
    layout.marginLeft = 10;
    layout.marginTop = 10;
    composite.setLayout(layout);
    
    Label label = new Label(composite, SWT.NONE);
    label.setText("Search parameters:");
    
    text = new Text(composite, SWT.BORDER);
    GridData data = new GridData();
    data.minimumWidth = 200;
    data.widthHint = 200;
    text.setLayoutData(data);
    
    checkBox = new Button(composite, SWT.CHECK);
    checkBox.setText("use regular expressions");
    data = new GridData();
    data.horizontalSpan = 2;
    checkBox.setLayoutData(data);
    
    return composite;
 }
	
	protected void configureShell(Shell newShell) {
    super.configureShell(newShell);
    newShell.setText("Enter search parameters.");
	}
	
	private void saveInput() {
		criteria = text.getText();
		useRegexec = checkBox.getSelection(); 
	}
	
	@Override
	protected void okPressed() {
		saveInput();
		super.okPressed();
	}
	
	public String getCriteria() {
		return criteria;
	}
	
	public boolean getUseRegexec() {
		return useRegexec;
	}

}
